﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "Window/u_mainpage.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //this->InitWidget();
    this->SetupConnections();
    this->Initialize();

    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
    this->setAttribute(Qt::WA_QuitOnClose);
    //this->setSizeGripEnabled(true);                  //设置可以拖拽大小
    this->setObjectName("mainWindow");
    this->resize(1200, 700);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::InitWidget(){

    menuBar = new MenuBar(this);
    statusBar = new StatusBar(this);

    stackedWidget = new QStackedWidget();//QStackedWidget小部件
    stackedWidget->setContentsMargins(5,5,5,5);//设置小部件边框
    stackedWidget->addWidget(new MainPage(this));
    stackedWidget->addWidget(new TCardPanel(this));

    QVBoxLayout *mainLayout = new QVBoxLayout();
    mainLayout->setMargin(0);//设置边距
    mainLayout->setSpacing(0);//设置间距
    mainLayout->addWidget(menuBar);
    mainLayout->addWidget(stackedWidget);
    mainLayout->addWidget(statusBar);
    this->setLayout(mainLayout);
}

void MainWindow::SetupConnections(){
    connect(menuBar, SIGNAL(ShowPage(int)), stackedWidget, SLOT(setCurrentIndex(int)));
}

void MainWindow::Initialize(){

}

//主窗体设置FramelessWindowHint后，窗体接收paint消息异常  app不刷新
void MainWindow::showEvent(QShowEvent* event){
    this->setAttribute(Qt::WA_Mapped);//小部件映射在屏幕上
    QWidget::showEvent(event);
}
